package com.kaishengit.dao;

import java.sql.ResultSet;
import java.sql.SQLException;

import com.kaishengit.entity.Employee_has_t_project;
import com.kaishengit.util.DBHelp;
import com.kaishengit.util.RowMapper;

public class Employee_has_t_projectDao {
	
	private DBHelp<Employee_has_t_project> db = new DBHelp<Employee_has_t_project>();
	
	public void Save (String t_employee_id,String t_project_id,String role) {
		String sql = "insert into t_employee_has_t_project(t_employee_id,t_project_id,role) values(?,?,?)";
		db.executeSQL(sql, t_employee_id,t_project_id,role);
	}
	
	public Employee_has_t_project FindRole (String t_employee_id,String t_project_id) {
		String sql = "select  t_employee_id,t_project_id,role from t_employee_has_t_project where t_employee_id = ? and t_project_id = ?";
		return db.executeQueryForObject(sql, new Employee_has_t_projectRowMapper(), t_employee_id,t_project_id);
	}
	private class Employee_has_t_projectRowMapper implements RowMapper<Employee_has_t_project> {
		
		public Employee_has_t_project mapperRow (ResultSet rs) throws SQLException {
			
			Employee_has_t_project emp_pro = new Employee_has_t_project();
			emp_pro.setT_employee_id(rs.getString("t_employee_id"));
			emp_pro.setT_project_id(rs.getString("t_project_id"));
			emp_pro.setRole(rs.getString("role"));
			return emp_pro;
		}
	}
}
